package apiFun

import (
	"fmt"
	"log"
	"net/http"

	"github.com/gin-gonic/gin"
)

func UploadFile(c *gin.Context) {
	file, err := c.FormFile("file")
	if err != nil {
		c.JSON(400, gin.H{
			"code":    400,
			"message": "参数错误",
		})
		return
	}
	log.Println(file.Filename)
	dst := fmt.Sprintf("./assets/imgs/%s", file.Filename)
	//上传文件到指定目录
	c.SaveUploadedFile(file, dst)
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "上传成功",
		"url":     fmt.Sprintf("/assets/imgs/%s", file.Filename),
	})
}
